package com.ruiboyun.liveapp.util.tool;

import android.content.Context;
import android.content.SharedPreferences;

import com.ruiboyun.liveapp.base.App;
import com.ruiboyun.liveapp.base.Url;


/**
 * Created by 吴世芊 on 2015/12/19 16:55.
 * 邮箱:apple9302@126.com
 * 公司:浙江答分奇网络技术有限公司
 * 项目名：DaFenQi
 * 包名：com.zhihuitong.dafenqi.toolclass
 * 类功能描述：
 */
public class EditorShare {

    public synchronized static String getString( String key) {
        SharedPreferences preferences = getPreference(App.getInstance());
        String value = preferences.getString(key, "");
        return value;
    }

    public synchronized static void putString( String key, String value) {
        SharedPreferences preferences = getPreference(App.getInstance());
        SharedPreferences.Editor editor = preferences.edit();
        editor.putString(key, value);
        editor.commit();
    }

    public synchronized static void removeKey( String key) {
        SharedPreferences preferences = getPreference(App.getInstance());
        SharedPreferences.Editor editor = preferences.edit();
        editor.remove(key);
        editor.commit();
    }

    public synchronized static void putBoolean( String key, boolean value) {
        SharedPreferences preferences = getPreference(App.getInstance());
        SharedPreferences.Editor editor = preferences.edit();
        editor.putBoolean(key, value);
        editor.commit();
    }

    public synchronized static boolean getBoolean( String key) {
        SharedPreferences preferences = getPreference(App.getInstance());
        boolean value = preferences.getBoolean(key, false);
        return value;
    }

    public synchronized static long getInt( String key) {
        SharedPreferences preferences = getPreference(App.getInstance());
        int value = preferences.getInt(key, 0);
        return value;
    }

    public synchronized static void putInt( String key, int value) {
        SharedPreferences preferences = getPreference(App.getInstance());
        SharedPreferences.Editor editor = preferences.edit();
        editor.putInt(key, value);
        editor.commit();
    }


    public synchronized static long getLong( String key) {
        SharedPreferences preferences = getPreference(App.getInstance());
        long value = preferences.getLong(key, 0);
        return value;
    }
    public synchronized static void putLong( String key, long value) {
        SharedPreferences preferences = getPreference(App.getInstance());
        SharedPreferences.Editor editor = preferences.edit();
        editor.putLong(key, value);
        editor.commit();
    }

    public synchronized static SharedPreferences getPreference(Context context) {
        SharedPreferences preferences = context.getSharedPreferences(Url.TABLE_NAME, Context.MODE_PRIVATE);
        return preferences;
    }
}
